//
//  ViewController.m
//  010-tableView自定义cell
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "ViewController.h"
#import "YMJTableViewCell.h"
#import "DataModel.h"
#import "SecondTableViewCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) NSMutableArray *nameArray;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationController.navigationBar.translucent = NO;
    DataModel *dataModel = [[DataModel alloc] initWithImageNameStr:@"29c092ea071401c7a817715c8705bdddfc8577af12ca2c-SHVj06_fw658" titleStr:@"你妹" titleStr1:@"你爹" titleStr2:@"你哥"];
    DataModel *dataModel1 = [[DataModel alloc] initWithImageNameStr:@"c8d0a47bfb10ec8f215b4ca49b2198725c3487d11571c-AWFaEh_fw658" titleStr:@"你妹" titleStr1:@"你爹" titleStr2:@"你哥"];

    DataModel *dataModel2 = [[DataModel alloc] initWithImageNameStr:@"e75cbc90a6036a043288159c2dda2af832fd00cf1a3dbc-2ByGIQ_fw658" titleStr:@"你妹" titleStr1:@"你爹" titleStr2:@"你哥"];
    DataModel *dataModel3 = [[DataModel alloc] initWithImageNameStr:@"1382021f2422472cd0fb596121b63f4b5b5cb06330d2e-HIaxOh_fw658" titleStr:@"你妹" titleStr1:@"你爹" titleStr2:@"你哥"];
    DataModel *datamodel4 = [[DataModel alloc] initWithImageNameStr:@"2108145399cb553b6a883e85b249325c2343b9bd11a55-4Re3Uv_fw658"];
     DataModel *datamodel5 = [[DataModel alloc] initWithImageNameStr:@"a5f5086487b0914d1e1367835181a0d3538c09e4129a6-vZE3NP_fw658"];
    NSArray *arr = @[dataModel2,dataModel,dataModel1,dataModel3,datamodel4,datamodel5];
    self.nameArray = [NSMutableArray arrayWithArray:arr];
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[YMJTableViewCell class] forCellReuseIdentifier:@"1"];
    [_tableView registerClass:[SecondTableViewCell class] forCellReuseIdentifier:@"2"];
    _tableView.contentInset = UIEdgeInsetsMake(0, 0, 64, 0);
    _tableView.rowHeight = 138;
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row) {
        return 330;
    } else {
        return 530;
    }
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _nameArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 多重cell同时使用,重用标识不要相同
    // 注意判断要完整,else 结尾,不要else if 之后 返回nil结尾
    if (indexPath.row  < 4) {
        YMJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"1" forIndexPath:indexPath];
        
        cell.backgroundColor = [UIColor whiteColor];
        cell.dataModel = _nameArray[indexPath.row];
        
        return cell;
       
    } else {
         SecondTableViewCell *secondCell = [tableView dequeueReusableCellWithIdentifier:@"2"];

        secondCell.dataModel = _nameArray[indexPath.row];
        return secondCell;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
